<template>
  <div>
    <storeDiyForm :title="diyItem.name" :hide="['other']">
      <template #content>
        <storeDiyFormItem label="布局">
          <storeDiyFormSelectBtn
            v-model="diyItem.layout.value"
            :data="layoutData"
          ></storeDiyFormSelectBtn>
        </storeDiyFormItem>
        <storeDiyFormItem label="展示形式">
          <storeDiyFormSelectBtn
            v-model="diyItem.layout.rows_num"
            :data="rowsData"
          ></storeDiyFormSelectBtn>
        </storeDiyFormItem>
        <div>
          <div>
            <p class="text-grey fz12">建议上传尺寸相同的图片(60px * 60px)</p>
          </div>
          <div class="mt20">
            <draggable v-model="diyItem.data" item-key="index">
              <template #item="{ element, index }">
                <storeDiyFormItems>
                  <storeDiyFormDeleteBtn
                    @click="onEditorDelele(index)"
                  ></storeDiyFormDeleteBtn>
                  <storeDiyFormItem label="标题" :hideAfter="true">
                    <el-input v-model="element.title" />
                  </storeDiyFormItem>
                  <storeDiyFormItem label="标题颜色" :hideAfter="true">
                    <storeDiyFormColorBtn v-model="element.color" />
                  </storeDiyFormItem>
                  <storeDiyFormItem label="标题加粗">
                    <storeDiyFormSelectBtn
                      v-model="element.fw"
                      :data="fwData"
                    ></storeDiyFormSelectBtn>
                  </storeDiyFormItem>
                  <storeDiyFormItem label="图片" :hideAfter="true">
                    <storeDiyFormImageBtn v-model="element.img">
                    </storeDiyFormImageBtn>
                  </storeDiyFormItem>
                  <storeDiyFormItem
                    label="跳转链接"
                    :hideAfter="true"
                    :marginBotton="false"
                  >
                    <storeDiyFormLinkBtn
                      text="选择跳转到的页面"
                      v-model="element.link"
                    >
                    </storeDiyFormLinkBtn>
                  </storeDiyFormItem>
                </storeDiyFormItems>
              </template>
            </draggable>
          </div>
          <storeDiyFormCreateBtn
            v-if="diyItem.data.length < diyItem.layout.rows_num"
            @click="onEditorAddData"
            text="添加一个"
          >
          </storeDiyFormCreateBtn>
        </div>
      </template>
      <template #style>
        <storeDiyFormItem label="背景状态">
          <storeDiyFormSelectBtn
            v-model="diyItem.style.bg_status"
            :data="bgStatusData"
          ></storeDiyFormSelectBtn>
        </storeDiyFormItem>
        <storeDiyFormItem label="背景颜色" v-if="diyItem.style.bg_status">
          <storeDiyFormColorBtn v-model="diyItem.style.bg" />
        </storeDiyFormItem>

        <storeDiyFormItem
          label="背景上圆角"
          v-if="diyItem.style.bg_status == 1"
        >
          <div class="editor-input-block">
            <div class="editor-input-desc">
              {{ diyItem.style.t_radius }}px(像素)
            </div>
            <el-slider
              v-model="diyItem.style.t_radius"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem
          label="背景下圆角"
          v-if="diyItem.style.bg_status == 1"
        >
          <div class="editor-input-block">
            <div class="editor-input-desc">
              {{ diyItem.style.b_radius }}px(像素)
            </div>
            <el-slider
              v-model="diyItem.style.b_radius"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>

        <storeDiyFormItem label="投影样式">
          <storeDiyFormSelectBtn
            v-model="diyItem.style.shade"
            :data="shadeData"
          ></storeDiyFormSelectBtn>
        </storeDiyFormItem>

        <el-divider content-position="left">
          <div class="fw">边距</div>
        </el-divider>

        <storeDiyFormItem label="外左边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.ml }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.ml"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>

        <storeDiyFormItem label="外右边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.mr }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.mr"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem label="外上边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.mt }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.mt"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem label="外下边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.mb }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.mb"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>

        <storeDiyFormItem label="内左边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.pl }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.pl"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem label="内右边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.pr }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.pr"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>

        <storeDiyFormItem label="内上边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.pt }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.pt"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
        <storeDiyFormItem label="内下边距">
          <div class="editor-input-block">
            <div class="editor-input-desc">{{ diyItem.style.pb }}px(像素)</div>
            <el-slider
              v-model="diyItem.style.pb"
              size="small"
              :min="0"
              :max="60"
            />
          </div>
        </storeDiyFormItem>
      </template>
    </storeDiyForm>
  </div>
</template>


<script lang="ts">
import { defineComponent } from "vue";
import draggable from "vuedraggable";
export default defineComponent({
  name: "storeDiyEditorNavBar",
  components: {
    draggable,
  },
});
</script>
<script  lang="ts" setup >
import { ref, getCurrentInstance } from "vue";
import storeDiyForm from "../form/index.vue";
import storeDiyFormItem from "../form/item.vue";
import storeDiyFormItems from "../form/items.vue";
import storeDiyFormImageBtn from "../form/image-btn.vue";
import storeDiyFormTempBtn from "../form/temp-btn.vue";
import storeDiyFormSelectBtn from "../form/select-btn.vue";
import storeDiyFormLinkBtn from "../form/link-btn.vue";
import storeDiyFormCreateBtn from "../form/create-btn.vue";
import storeDiyFormDeleteBtn from "../form/delete-btn.vue";
import storeDiyFormColorBtn from "../form/color-btn.vue";

import { diySelectDataType, diyNavBarDataType } from "@/types";

const {
  proxy: { $utils },
} = getCurrentInstance() as any;

const props = withDefaults(
  defineProps<{
    diyItem: diyNavBarDataType;
  }>(),
  {
    diyItem: () => {
      return {
        layout: {
          value: 1,
          rows_num: 4,
        },
        style: {
          bg_status: 1,
          bg: "",
          shade: 0,
          mt: 0,
          mb: 0,
          ml: 0,
          mr: 0,
          pt: 0,
          pb: 0,
          pl: 0,
          pr: 0,
          t_radius: 0,
          b_radius: 0,
        },
        data: [],
        default_data: {
          title: "",
          img: "",
          link: {},
          fw: 0,
          color: "",
        },
      };
    },
  }
);

const layoutData = ref<Array<diySelectDataType>>([
  {
    title: "图片导航",
    value: 1,
  },
  {
    title: "文字导航",
    value: 2,
  },
]);

const rowsData = ref<Array<diySelectDataType>>([
  {
    title: "三个",
    value: 3,
  },
  {
    title: "四个",
    value: 4,
  },
  {
    title: "五个",
    value: 5,
  },
]);

const fwData = ref<Array<diySelectDataType>>([
  {
    title: "默认",
    value: 0,
  },
  {
    title: "加粗",
    value: 1,
  },
]);

const bgStatusData = ref<Array<diySelectDataType>>([
  {
    title: "显示",
    value: 1,
  },
  {
    title: "不显示",
    value: 0,
  },
]);

const shadeData = ref<Array<diySelectDataType>>([
  {
    title: "常规",
    value: 0,
  },
  {
    title: "投影",
    value: 1,
  },
]);

const emit = defineEmits(["onEditorAdd", "onEditorDelele"]);

/**
 * 编辑器：添加data元素
 */
const onEditorAddData = () => {
  emit("onEditorAdd", {
    count: props.diyItem.layout.rows_num,
    type: "nav_bar",
  });
};

const onEditorDelele = (index: number) => {
  emit("onEditorDelele", {
    index,
    key: "data",
  });
};
</script>